define(function() {
	var Ajax = function() {

		this.requests = [];

	};

	Ajax.prototype = {

		XMLHttpRequest : function() {
			//If XMLHttpRequest is available then using it
			if (typeof XMLHttpRequest !== undefined) {
				return new XMLHttpRequest;
			//if window.ActiveXObject is available than the user is using IE...so we have to create the newest version XMLHttp object
			} else if (window.ActiveXObject) {
				var ieXMLHttpVersions = ['MSXML2.XMLHttp.5.0', 'MSXML2.XMLHttp.4.0', 'MSXML2.XMLHttp.3.0', 'MSXML2.XMLHttp', 'Microsoft.XMLHttp'], xmlHttp;
				//In this array we are starting from the first element (newest version) and trying to create it. If there is an
				//exception thrown we are handling it (and doing nothing ^^)
				for (var i = 0; i < ieXMLHttpVersions.length; i++) {
					try {
						xmlHttp = new ActiveXObject(ieXMLHttpVersions[i]);
						return xmlHttp;
					} catch (e) {
					}
				}
			}
		},

		execute : function(args) {

			args = args || {};

			var url = args.url || null,
				data = args.data || null,
				type = args.type || "get",
				success = args.success || function(){},
				error = args.error || function(){};

			url = type === "get" ? url + "?" + data : url;

			var request = this.XMLHttpRequest(success, error);
			request.open(type, url, true);

			if(type === "post" && data !== null) {
				//Send the proper header information along with the request
				request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			}

			request.send(data);
			
			request.onreadystatechange = function() {
				if (request.readyState === 4) {
					if (request.status === 200) {
						success.call(null, request.responseText);
					} else {
						error.call(null, request.responseText);
					}
				} else {
					//still processing
				}
			};

			this.requests.push(request);
		}
	};

	return Ajax;
});